@using Radzen.Blazor.Rendering
<g class="rz-arc-gauge-scale">
<GaugeScale
    Radius=@CurrentScaleRadius
    StrokeWidth=@CurrentStrokeWidth
    Stroke=@Stroke
    Center=@CurrentCenter
    StartAngle=@StartAngle
    EndAngle=@EndAngle
    TickPosition=@TickPosition
    ShowFirstTick=@ShowFirstTick
    ShowLastTick=@ShowLastTick
    ShowTickLabels=@ShowTickLabels
    TickLength=@TickLength
    TickLabelOffset=@TickLabelOffset
    Min=@Min
    Max=@Max
    Step=@Step
    MinorStep=@MinorStep
    FormatString=@FormatString
    Formatter=@Formatter
    MinorTickLength=@MinorTickLength
/>
<GaugeBand 
    From=@Min
    To=@Max
    Fill=@Fill
    Stroke=@Stroke
    StrokeWidth=@CurrentStrokeWidth
    Radius=@CurrentRadius
    Center=@CurrentCenter
    StartAngle=@StartAngle
    EndAngle=@EndAngle
    Min=@Min
    Max=@Max
    Size=@CurrentSize
/>
</g>
<CascadingValue Value=@this>
    @ChildContent
</CascadingValue>
@code {
    [CascadingParameter]
    public RadzenArcGauge Gauge { get; set; }

    [Parameter]
    public string Stroke { get; set; }

    [Parameter]
    public double StrokeWidth { get; set; } = 1;

    [Parameter]
    public RenderFragment ChildContent { get; set; }

    [Parameter]
    public double TickLength { get; set; } = 10;

    [Parameter]
    public double MinorTickLength { get; set; } = 5;

    [Parameter]
    public double TickLabelOffset { get; set; } = 25;

    [Parameter]
    public string FormatString { get; set; }

    [Parameter]
    public string Fill { get; set; }

    [Parameter]
    public double Height { get; set; } = 0.2;

    [Parameter]
    public Func<double, string> Formatter { get; set; } = value => value.ToString();

    [Parameter]
    public double StartAngle { get; set; } = -90;

    [Parameter]
    public GaugeTickPosition TickPosition { get; set; } = GaugeTickPosition.None;

    [Parameter]
    public double EndAngle { get; set; } = 90;

    [Parameter]
    public double Radius { get; set; } = 1;

    [Parameter]
    public bool ShowFirstTick { get; set; } = true;

    [Parameter]
    public bool ShowLastTick { get; set; } = true;

    [Parameter]
    public bool ShowTickLabels { get; set; } = true;

    [Parameter]
    public double X { get; set; } = 0.5;

    [Parameter]
    public double Min { get; set; } = 0;

    [Parameter]
    public double Max { get; set; } = 100;

    [Parameter]
    public double Step { get; set; } = 20;

    [Parameter]
    public double MinorStep { get; set; }

    [Parameter]
    public double Y { get; set; } = 0.5;

    [Parameter]
    public double Margin { get; set; } = 16;

    public double CurrentStrokeWidth
    {
        get
        {
            if (TickPosition == GaugeTickPosition.None)
            {
                return 0;
            }

            return StrokeWidth;
        }
    }

    public double CurrentRadius
    {
        get
        {
            var radius = Math.Min(Gauge.Width.Value, Gauge.Height.Value) / 2 - Margin * 2;

            radius *= Radius;

            if (TickPosition == GaugeTickPosition.Outside)
            {
                radius -= TextMeasurer.TextWidth(Max.ToString(), 16);
            }

            return radius;
        }
    }


    double CurrentScaleRadius
    {
        get
        {
            if (TickPosition == GaugeTickPosition.Inside)
            {
                return CurrentRadius - CurrentSize;
            }

            return CurrentRadius;
        }
    }

    public double CurrentSize
    {
        get
        {
            var radius = Math.Min(Gauge.Width.Value, Gauge.Height.Value) / 2 - Margin * 2;

            if (TickPosition == GaugeTickPosition.Outside)
            {
                radius -= TextMeasurer.TextWidth(Max.ToString(), 16);
            }

            return radius * Height;
        }
    }

    public Point CurrentCenter
    {
        get
        {
            var x = X * Gauge.Width;
            var y = Y * Gauge.Height;

            return new Point { X = x.Value, Y = y.Value };
        }
    }
}
